package com.renu.jdependencyanalyser.window;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowFactory;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentFactory;
import com.renu.jdependencyanalyser.cons.DefaultFileCons;
import com.renu.jdependencyanalyser.data.ProjectDataCenter;
import com.renu.jdependencyanalyser.utils.MyFileUtil;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import java.awt.*;
import java.net.URL;

public class AnalyserWindowFactory implements ToolWindowFactory {
    @Override
    public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
        //JLabel imageLabel = new JLabel();
        //ImageIcon imageIcon = createImageIcon(DefaultFileCons.SAMPLE_OUTER_CLASS);
        //imageLabel.setIcon(imageIcon);

        AnalyserWindow analyserWindow = new AnalyserWindow(project, toolWindow);
        ProjectDataCenter.analyserWindow = analyserWindow;
        JPanel contentPanel = analyserWindow.getContentPanel();
        //analyserWindow.getImagePanel().add(imageLabel, BorderLayout.CENTER);

        ContentFactory contentFactory = ContentFactory.getInstance();
        Content content = contentFactory.createContent(contentPanel, "", false);
        toolWindow.getContentManager().addContent(content);

    }

    //private  ImageIcon createImageIcon(String path) {
    //    URL imageUrl = AnalyserWindowFactory.class.getResource(path);
    //    if (imageUrl != null) {
    //        return new ImageIcon(imageUrl);
    //    } else {
    //        System.err.println("Couldn't find image: " + path);
    //        return null;
    //    }
    //}
}
